import service from '@/utils/request'

/**
 * 登录
 * @param {*} data 登录表单数据	
 * username
 * password
 * key
 * captcha
 * @returns
 */
export const login = (params) => {
  return service({
    url: '/api/sys/auth_login',
    method: 'post',
    params
  })
}

/**
 * 获取登录者信息
 */
export const getUserInfo = (params) => {
  return service({
    url: '/api/sys/user_info',
    method: 'get',
    params
  })
}

/**
 * 修改用户自身的一些信息，比如修改头像和修改密码
 *  avatar      string `json:"avatar" form:"avatar"`
 *  password    string `json:"password" form:"password" binding:"required,min=4"`
 *  newPassword string `json:"newPassword" form:"newPassword" binding:"required,min=4"
 */
export const updateUserInfo = (data) => {
  return service({
    url: '/api/sys/user_info',
    method: 'put',
    data
  })
}

/**
 * 退出登录
 */
export const logout = () => {
  return service({
    url: '/api/sys/auth_logout',
    method: 'get'
  })
}

/**
 * 获取用户列表
 * username、mobile、gender 这三个是查询参数
 * PageOrderParam 分页参数
 * 参数包括：order、asc、page、limit
 */
export const getUserList = (params) => {
  return service({
    url: '/api/sys/user_page',
    method: 'get',
    params
  })
}

/**
 * 新增用户
 *  id         uint   `json:"id"`
 *  username   string `json:"username" binding:"required,min=4,max=20"`
 *  realName   string `json:"realName" binding:"required,min=2,max=20"`
 *  orgId      int    `json:"orgId" binding:"required"`
 *  orgName    string `json:"orgName"`
 *  password   string `json:"password"`
 *  gender     any    `json:"gender"`
 *  email      string `json:"email"`
 *  mobile     string `json:"mobile" binding:"required,min=11"`
 *  roleIdList []uint `json:"roleIdList"`
 *  postIdList []uint `json:"postIdList"`
 *  status     int8   `json:"status
 */
export const addUser = (data) => {
  return service({
    url: '/api/sys/user',
    method: 'post',
    data
  })
}

/**
 * 修改用户
 *  id         uint   `json:"id"`
 *  username   string `json:"username" binding:"required,min=4,max=20"`
 *  realName   string `json:"realName" binding:"required,min=2,max=20"`
 *  orgId      int    `json:"orgId" binding:"required"`
 *  orgName    string `json:"orgName"`
 *  password   string `json:"password"`
 *  gender     any    `json:"gender"`
 *  email      string `json:"email"`
 *  mobile     string `json:"mobile" binding:"required,min=11"`
 *  roleIdList []uint `json:"roleIdList"`
 *  postIdList []uint `json:"postIdList"`
 *  status     int8   `json:"status
 */
export const updateUser = (data) => {
  return service({
    url: '/api/sys/user',
    method: 'put',
    data
  })
}

/**
 * 删除用户
 * id_arr []int64 
 */
export const deleteUser = (ids) => {
  return service({
    url: '/api/sys/user',
    method: 'delete',
    params: { id_arr: ids }
  })
}

/**
 * 获取一个用户
 * id int64
 */
export const getUser = (id) => {
  return service({
    url: '/api/sys/user',
    method: 'get',
    params: { id }
  })
}
